Skip to content

feat: add ObjectContexts to Blob#1767

Draft
nidhiii-27 wants to merge 2 commits intomainfrom
feat-object-contexts-1046589087761828711
Draft

feat: add ObjectContexts to Blob#1767
nidhiii-27 wants to merge 2 commits intomainfrom
feat-object-contexts-1046589087761828711

Conversation

@nidhiii-27
Copy link
Contributor

This PR adds the Object Contexts feature, implementing strongly-typed payloads for arbitrary context configuration mimicking the Java storage client's implementation.

  • Created google/cloud/storage/contexts.py specifying the schema for ObjectContexts and ObjectCustomContextPayload.
  • Exposed the contexts property on Blob objects which performs mapping to underlying properties for patching.
  • Included robust tests assessing mapping flat vs deep payload representations.

PR created automatically by Jules for task 1046589087761828711 started by @nidhiii-27

Added the `ObjectContexts` and `ObjectCustomContextPayload` classes to represent user-defined object contexts, analogous to Java's `ObjectContexts`. Added `contexts` getter and setter to `Blob` class which automatically formats and parses dictionaries to the expected API representation. Integrated the corresponding system and unit tests.

Co-authored-by: nidhiii-27 <224584462+nidhiii-27@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@nidhiii-27 nidhiii-27 requested review from a team as code owners March 8, 2026 16:22
@product-auto-label product-auto-label bot added the size: l Pull request size is large. label Mar 8, 2026
@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/python-storage API. label Mar 8, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the Google Cloud Storage Python client by adding support for Object Contexts on Blob objects. This feature provides a structured and strongly-typed mechanism for associating custom, arbitrary data with objects, bringing the Python client's capabilities in line with other language clients like Java. The changes involve defining new data structures for contexts and integrating them seamlessly into the existing Blob API for easy management.

Highlights

  • New Feature: Object Contexts: Introduced the Object Contexts feature to the Blob object, allowing for strongly-typed payloads for arbitrary context configuration, mirroring the Java storage client's implementation.
  • New Module for Contexts: Created google/cloud/storage/contexts.py to define the schema for ObjectContexts and ObjectCustomContextPayload.
  • Blob Integration: Exposed a new contexts property on Blob objects, which handles the mapping to underlying properties for patching operations.
  • Comprehensive Testing: Included robust system and unit tests to assess the mapping of both flat and deep payload representations for object contexts.
Changelog
  • google/cloud/storage/blob.py
    • Imported ObjectContexts and ObjectCustomContextPayload from the new contexts module.
    • Added a new @property and @contexts.setter to the Blob class, enabling retrieval and setting of object contexts.
    • Implemented logic within the setter to handle various input types for contexts, including ObjectContexts instances, dictionaries, and None.
  • google/cloud/storage/contexts.py
    • Added a new file contexts.py to define the ObjectCustomContextPayload class for individual context entries.
    • Added the ObjectContexts class to manage a collection of custom object contexts.
    • Included _from_api_resource and _to_api_resource methods in both classes for serialization and deserialization with the API.
  • tests/system/test_blob.py
    • Added a new system test test_blob_contexts to verify the end-to-end functionality of setting, updating, and deleting object contexts on a blob.
  • tests/unit/test_blob.py
    • Added test_contexts_getter to verify correct parsing of API responses into ObjectContexts objects.
    • Added test_contexts_setter_w_dict to confirm proper handling of dictionary assignments to the contexts property.
    • Added test_contexts_setter_w_object_contexts to ensure ObjectContexts instances are correctly processed by the setter.
    • Added test_contexts_setter_none to validate that assigning None to contexts correctly clears the property.
Activity
  • The pull request was automatically created by Jules for a task initiated by @nidhiii-27.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@nidhiii-27 nidhiii-27 marked this pull request as draft March 8, 2026 16:23
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the Object Contexts feature, which is a great addition for parity with the Java client. The implementation looks solid, with new classes for ObjectContexts and ObjectCustomContextPayload, and the necessary integration into the Blob object. The tests are also comprehensive, covering both unit and system-level verification.

I have a couple of suggestions to improve code maintainability by reducing some code duplication and simplifying logic, and ensuring proper handling of mutable dictionary parameters. Overall, this is a well-executed feature.

Added the strongly-typed `ObjectContexts` and `ObjectCustomContextPayload` schema classes to interact with the new `contexts` field on Google Cloud Storage `Blob` objects. Integrated these changes as a property on the `Blob` class which automatically resolves updates and patches for dictionaries mapping configurations to explicit subclasses. Added system and unit tests mimicking existing configurations.

Co-authored-by: nidhiii-27 <224584462+nidhiii-27@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the googleapis/python-storage API. size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants